package com.whfc.iot.fse.lift.codec;

import com.whfc.iot.fse.lift.entity.LiftMsg;
import com.whfc.iot.fse.lift.util.LiftMsgUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 升降机消息解码器
 */
public class LiftMsgDecoder extends MessageToMessageDecoder<ByteBuf> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
        if (!in.isReadable()) {
            return;
        }
        logger.info("接收升降机数据:{}", ByteBufUtil.prettyHexDump(in));
        LiftMsg msg = LiftMsgUtil.decode(in);

        out.add(msg);
    }

}
